/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import pojo.Arquivos;

/**
 *
 * @author samuel
 */
public class DAOArquivo extends DAOGenerics<Arquivos, Integer> {

    @Override
    protected Arquivos buscar(Integer obj) {
        SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
        Session s = sf.openSession();

        try {
            return buscar(obj, s);

        } finally {
            s.close();
        }
    }

    @Override
    protected Arquivos buscar(Integer obj, Session s) {
        String sql = "from Arquivos where id = :id";

        Query qr = s.createQuery(sql);
        qr.setParameter("id", obj);

        return (Arquivos) qr.uniqueResult();
    }

    @Override
    protected List<Arquivos> buscarTodos() {
        SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
        Session s = sf.openSession();

        try {
            return buscarTodos(s);

        } finally {
            s.close();
        }
    }

    @Override
    protected List<Arquivos> buscarTodos(Session s) {
        String sql = "from Arquivos";

        Query qr = s.createQuery(sql);

        return (List<Arquivos>) qr.list();
    }
}
